﻿// -----------------------------------------------------------------------
// <copyright file="DatabaseScalarProducerBase.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Dhgms.TplHelper.Model.DatabaseScalarProducer
{
    using System;
    using System.Collections.Generic;
    using System.Data.Common;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class DatabaseScalarProducerBase<TParameter, TDataResultType> : IDatabaseScalarProducer<TDataResultType>
        where TParameter : DbParameter
    {
        protected DatabaseScalarProducerBase(string databaseConnectionString, bool assumeSqlSafe)
        {
            if (string.IsNullOrWhiteSpace(databaseConnectionString))
            {
                throw new ArgumentNullException("databaseConnectionString");
            }

            this.DatabaseConnectionString = databaseConnectionString;
            this.AssumeSqlSafe = assumeSqlSafe;
        }

        /// <summary>
        /// Gets the database connection string.
        /// </summary>
        protected string DatabaseConnectionString { get; private set; }

        /// <summary>
        /// Gets a flag indicating whether to assume the SQL is safe
        /// </summary>
        protected bool AssumeSqlSafe { get; private set; }
        
        /// <summary>
        /// Gets the SQL Command
        /// </summary>
        protected abstract string SqlCommand { get; }

        /// <summary>
        /// Gets the SQL parameters
        /// </summary>
        protected abstract TParameter[] SqlParameters { get; }

        /// <summary>
        /// Gets the scalar result
        /// </summary>
        /// <returns>The Scalar Result</returns>
        public abstract TDataResultType GetResult();
    }
}
